from odoo import models, api, _
from odoo.exceptions import ValidationError
from odoo.tools import float_compare


class SaleOrderLine(models.Model):
    _inherit = 'sale.order.line'

    @api.constrains('qty_delivered')
    def constrains_qty_delivered(self):
        for rec in self:
            if float_compare(rec.qty_delivered, 0, precision_rounding=rec.product_uom.rounding) == -1:
                raise ValidationError(_('The delivered quantity cannot be negative!'))
